package com.combetter.changxing.net.service;

import com.combetter.changxing.db.entity.User;
import com.combetter.changxing.model.City;
import com.combetter.changxing.model.Firmware;
import com.combetter.changxing.model.History;
import com.combetter.changxing.model.Image;
import com.combetter.changxing.model.Smoke;
import com.combetter.changxing.net.HttpResult;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

/**
 * 接口
 * <p>
 * Created by 深圳唐龙飞讯科技有限公司 on 2018/7/4.
 */
public interface APIService {

    /**
     * 登录
     *
     * @return
     */
    @POST("login.do")
    @FormUrlEncoded
    Observable<HttpResult<User>> login(@FieldMap HashMap<String, String> map);

    /**
     * 注册
     *
     * @return
     */
    @POST("register.do")
    @FormUrlEncoded
    Observable<HttpResult> register(@FieldMap HashMap<String, String> map);

    /**
     * 修改手机号
     *
     * @return
     */
    @POST("upPhone.do")
    @FormUrlEncoded
    Observable<HttpResult> alterPhone(@FieldMap HashMap<String, String> map);

    /**
     * 发送验证码
     *
     * @param phone  手机号
     * @param status 状态码(1：注册时, 2：找回密码时 3,更换手机号时 )
     * @returnPOST /api/
     */
    @POST("sms/sendCode")
    @FormUrlEncoded
    Observable<HttpResult> sendCode(@Field("phone") String phone, @Field("type") int status);

    /**
     * 城市列表
     *
     * @param map
     * @return
     */
    @GET("selectRegion.do")
    Observable<HttpResult<List<City>>> selectRegion(@QueryMap HashMap<String, Integer> map);

    /**
     * 忘记密码
     *
     * @param phone        手机号
     * @param password_new 新密码
     * @return
     */
    @POST("forgetUserAccount.do")
    @FormUrlEncoded
    Observable<HttpResult> forgetUserPwd(@Field("phone") String phone, @Field("password_new") String password_new, @Field("code") String code);


    /**
     * 上传文件
     *
     * @param avatar
     * @return
     */
    @POST("upload/fileUpload")
    @Multipart
    Observable<HttpResult<Image>> fileUpload(@Part() MultipartBody.Part avatar);

    /**
     * 获取用户信息
     *
     * @param uid
     * @return
     */
    @GET("selectUserDetails.do")
    Observable<HttpResult<User>> getUserInfo(@Query("uid") String uid);


    /**
     * 修改密码
     *
     * @param map
     * @return
     */
    @POST("resetPassword.do")
    @FormUrlEncoded
    Observable<HttpResult> resetPassword(@FieldMap HashMap<String, String> map);

    /**
     * 查询设备
     *
     * @param map type  1：操作设备
     * @return
     */
//    @POST("selectModel.do")
//    @FormUrlEncoded
//    Observable<HttpResult<List<FacilityModel>>> selectFacility(@FieldMap HashMap<String, String> map);

    /**
     * 查询收藏设备
     *
     * @param map
     * @return
     */
    @POST("queryUidAllSmoke")
    @FormUrlEncoded
    Observable<HttpResult> queryUidAllSmoke(@FieldMap HashMap<String, Object> map);

    /**
     * 取消收藏
     *
     * @param map
     * @return
     */
    @POST("updateSmoke")
    @FormUrlEncoded
    Observable<HttpResult> updateSmoke(@FieldMap HashMap<String, Object> map);

    /**
     * 切换当前收藏
     *
     * @param map
     * @return
     */
    @POST("updateType")
    @FormUrlEncoded
    Observable<HttpResult> updateType(@FieldMap HashMap<String, Object> map);

    /**
     * 查询历史吸烟记录
     *
     * @param map
     * @return
     */
    @POST("selectCtimeSmokeCount")
    @FormUrlEncoded
    Observable<HttpResult<History>> selectHistory(@FieldMap HashMap<String, Object> map);

    /**
     * 修改设备/添加设备
     *
     * @param map type  1：操作设备  2:收藏设备 status 1:增加   2:修改
     * @return
     */
    @POST("insertModel.do")
    @FormUrlEncoded
    Observable<HttpResult> insertFacility(@FieldMap HashMap<String, Object> map);

    /**
     * 删除设备/删除收藏设备
     *
     * @param mid  设备唯一标识
     * @param uid  用户id
     * @param type 1：删除设备   2:删除收藏
     * @return
     */
    @POST("deleteModel.do")
    @FormUrlEncoded
    Observable<HttpResult> deleteFacility(@Field("mid") int mid, @Field("uid") String uid, @Field("type") int type);

    /**
     * 获取固件 版本列表
     *
     * @param uid
     * @param type 1：客户端   2:后台
     * @return
     */
    @GET("selectGujian.do")
    Observable<HttpResult<List<Firmware>>> getFirmware(@Query("uid") String uid, @Query("identifierid") String identifier_id, @Query("type") int type);

    /**
     * 获取当前品牌香烟
     *
     * @param map
     * @return
     */
    @POST("selectUidType")
    @FormUrlEncoded
    Observable<HttpResult<Smoke>> selectUidType(@FieldMap HashMap<String, Object> map);

    /**
     * 扫一扫
     *
     * @param map
     * @return
     */
    @POST("selectSmokeMessage")
    @FormUrlEncoded
    Observable<HttpResult<Smoke>> selectSmokeMessage(@FieldMap HashMap<String, Object> map);

    /**
     * 吸烟记录
     *
     * @param map
     * @return
     */
    @POST("selectUidSmokeSum")
    @FormUrlEncoded
    Observable<HttpResult> selectUidSmokeSum(@FieldMap HashMap<String, Object> map);

    /**
     * 发送香烟抽吸数据
     *
     * @param map
     * @return
     */
    @POST("addSmokeCount")
    @FormUrlEncoded
    Observable<HttpResult> addSmokeCount(@FieldMap Map<String, String> map);
    /**
     * 【APP】获取消息列表
     *
     * @param map pageNum  pageSize uid
     * @return
     */
    @POST("getMsgList")
    @FormUrlEncoded
    Observable<HttpResult> getMsgList(@FieldMap Map<String, Object> map);
    /**
     * 【APP】获取消息详情
     * @param map id
     * @return
     */
    @POST("getMsgInfo")
    @FormUrlEncoded
    Observable<HttpResult> getMsgInfo(@FieldMap Map<String, String> map);

    @GET
    @Streaming    //使用Streaming 方式 Retrofit 不会一次性将ResponseBody 读取进入内存，否则文件很多容易OOM
    Observable<ResponseBody> download2(@Url String url);  //返回值使用 ResponseBody 之后会对ResponseBody 进行读取
}
